1f<?php 
    header("Content-type:text/html;charset=utf-8");


function connect(){
        define('DB_HOST','localhost');
        define('DB_USER','root');
        define('DB_PWD','');
        define('DB_CHARSET','UTF8');
        define('DB_DBNAME','neo_video');
        $link=@mysql_connect(DB_HOST,DB_USER,DB_PWD) or die('数据库连接失败</br>'.mysql_errno().':'.mysql_error());
        mysql_set_charset(DB_CHARSET);
        mysql_select_db(DB_DBNAME) or die('该数据库打开失败'.mysql_error());
        return $link;
}
function add($tbl,$data){
	$keys=implode(',',array_keys($data));
	$values=implode("','",array_values($data));
	$sql="insert into {$tbl}({$keys}) values ('{$values}')";
	$result=mysql_query($sql);
	if($result===FALSE){
		return false;
	}
	else{
		return mysql_insert_id();
	}
}
function update($tbl,$data,$where=null){
	foreach ($data as $key => $val) {
		$sets.=$key."='".$val."',";
	}
	$sets=rtrim($sets,',');
	$where=$where==null?'':'WHERE '.$where;
	$sql="update {$tbl} set {$sets} {$where}";
    $result=mysql_query($sql);
    if($result){
    	return mysql_affected_rows();
    }
    else {
    	return false;
    }
}
function delete($tbl,$where=null){
	$where=$where==null?'':'WHERE '.$where;
	$sql="delete from {$tbl}{$where}";
	$result=mysql_query($sql);
	if($result){
		return mysql_affected_rows();
	}
	else{
		return false;
	}
}
function fetch_one($sql,$result_type=MYSQL_ASSOC){
	$result=mysql_query($sql);
	if($result && mysql_num_rows($result)>0){
		return mysql_fetch_array($result,$result_type);
	}
	else{
		return false;
	}
}
function fetch_array($sql,$result_type=MYSQL_ASSOC){
	$result=mysql_query($sql);
	if($result && mysql_num_rows($result)>0){
		while ($row=mysql_fetch_array($result,$result_type)) {
			$rows[]=$row;
		}
		return $rows;
	}
	else{
		return false;
	}
}
function getTotalRows($sql){
	$result=mysql_query($sql);
	if($result){
		return mysql_num_rows($result);
	}else{
		return false;
	}
}
function freeResult($result){
	return mysql_free_result($result);
}
function close($link=null){
	return mysql_close($link);
}




 ?>
